/***************************************
	文件：GoapPreEff.cs
	作者：林文豪
	日期：2021-05-09
	功能：1、
****************************************/

using System;
using System.Collections.Generic;
using System.Linq;

namespace MyGame.AI.GOAP {
    public class GoapCondition : IEquatable<GoapCondition> {
	    public readonly List<GoapConditionContainer> AllConditionContainers;
	    
	    public GoapCondition(List<GoapConditionContainer> dic) {
		    AllConditionContainers = new List<GoapConditionContainer>(dic);
	    }

	    public bool CanLink(GoapCondition other) {
		    foreach (GoapConditionContainer thisCondition in AllConditionContainers) {
			    bool isSatisfy = false;
			    foreach (GoapConditionContainer otherCondition in other.AllConditionContainers) {
				    if (thisCondition.Equals(otherCondition)) {
					    isSatisfy = true;
					    break;
				    }
			    }
			    if (isSatisfy == false) {
				    return false;
			    }
		    }

		    return true;
	    }

	    public bool Equals(GoapCondition other) {
		    if (other == null || other.AllConditionContainers == null) {
			    return false;
		    }
		    foreach (GoapConditionContainer container in AllConditionContainers) {
			    if (other.AllConditionContainers.Contains(container) == false) {
				    return false;
			    }
		    }

		    return true;
	    }
    }
}
